#include "cybertron/sensor/noise/CompositeNoise.hpp"

CYBERTRON_BEGIN


CompositeNoise::CompositeNoise()
	:NoiseBase(ECompositeNoise)
{
}

CompositeNoise::CompositeNoise(const NoiseBases& noises)
	:NoiseBase(ECompositeNoise), m_noises(noises)
{
}

CompositeNoise::~CompositeNoise()
{
}

vec3 CompositeNoise::update()
{
	vec3 noiseValue(0.0);
	for (auto pNoise : m_noises) {
		noiseValue += pNoise->update();
	}
	m_value = noiseValue;
	return m_value;
}

void CompositeNoise::resetNoise()
{
	for (auto pNoise : m_noises) {
		pNoise->resetNoise();
	}
}

void CompositeNoise::addNoise(NoiseBasePtr pNoise)
{
	m_noises.emplace_back(pNoise);
}

const NoiseBases& CompositeNoise::allNoises() const
{
	return m_noises;
}

NoiseBasePtr CompositeNoise::getNoise(NoiseType noiseType) const
{
	for (auto pNoise : m_noises) {
		if (pNoise->noiseType() == noiseType) {
			return pNoise;
		}
	}
	return nullptr;
}


CYBERTRON_END